﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.Messages {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="AnnaSeotudKlassifikaatoridResponse", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(AnnaSeotudKlassifikaatoridResponse))]
    public class AnnaSeotudKlassifikaatoridResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IAnnaSeotudKlassifikaatoridResponse clazz;
        
        public AnnaSeotudKlassifikaatoridResponseSerializer(IAnnaSeotudKlassifikaatoridResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Paring!=null) {
                Writer.WriteStartElement("paring");
                global::Xtee.Core.SerializationMetadata metaParing = this.GetMetaData(clazz.Paring);
                Writer.WriteTypeAttribute(metaParing.TypeQualifiedName.Namespace, metaParing.TypeQualifiedName.Name);
                metaParing.NewSerializer(clazz.Paring).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("keha");
            if (clazz.Keha!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("SeotudKlassifikaatorid", "http://producers.etoimik.xtee.riik.ee/producer/etoimik", clazz.Keha.Count);
                for (int x = 0; ((clazz.Keha != null) 
                            && (x < clazz.Keha.Count)); x = (x + 1)) {
                    if (clazz.Keha[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaKeha = this.GetMetaData(clazz.Keha[x]);
                        Writer.WriteTypeAttribute(metaKeha.TypeQualifiedName.Namespace, metaKeha.TypeQualifiedName.Name);
                        metaKeha.NewSerializer(clazz.Keha[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            if (clazz.P2!=null) {
                Writer.WriteStartElement("p2");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "base64Binary");
                Writer.WriteString(new global::Xtee.Core.Schema.SOAPBase64Binary(((byte[])(clazz.P2))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="paring") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaParing = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IAnnaSeotudKlassifikaatoridParing>(Reader, "AnnaSeotudKlassifikaatoridParing", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                    clazz.Paring = metaParing.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IAnnaSeotudKlassifikaatoridParing>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("paring");
                        metaParing.NewSerializer(clazz.Paring).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="keha") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Keha = new System.Collections.Generic.List<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.ISeotudKlassifikaatorid>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("keha");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaKeha = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.ISeotudKlassifikaatorid>(Reader, "SeotudKlassifikaatorid", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                                global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.ISeotudKlassifikaatorid item = metaKeha.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.ISeotudKlassifikaatorid>();
                                clazz.Keha.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    Reader.ReadStartElement("item");
                                    metaKeha.NewSerializer(item).ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.Keha.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">keha", Reader.LocalName);
            }
            if (Reader.LocalName=="p2") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.P2 = new global::Xtee.Core.Schema.SOAPBase64Binary(Reader.ReadElementString("p2")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
